/**
* @author:kellen
* @contact:xiekellen@hotmail.com
* @company:achivo-gz
* @created on:
* @modified on:
*/

package com.sasis.dao.ibatis;

import java.util.List;

import com.sasis.dao.ibatis.BaseDaoiBATIS;
import com.sasis.model.FlightTransInstruction;
import com.sasis.dao.FlightTransInstructionDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class FlightTransInstructionDaoiBatis extends BaseDaoiBATIS implements FlightTransInstructionDao {

    /**
     * @see com.sasis.dao.FlightTransInstructionDao#getFlightTransInstructions(com.sasis.model.FlightTransInstruction)
     */
    public List getFlightTransInstructions(final FlightTransInstruction flightTransInstruction) {
          return getSqlMapClientTemplate().queryForList("getFlightTransInstructions", flightTransInstruction);
    }

    /**
     * @see com.sasis.dao.FlightTransInstructionDao#getFlightTransInstruction(Integer id)
     */
    public FlightTransInstruction getFlightTransInstruction(Integer id) {
        FlightTransInstruction flightTransInstruction = (FlightTransInstruction) getSqlMapClientTemplate().queryForObject("getFlightTransInstruction", id);

        //if (flightTransInstruction == null) {
            //throw new ObjectRetrievalFailureException(FlightTransInstruction.class, id);
        //}

        return flightTransInstruction;
    }

    /**
     * @see com.sasis.dao.FlightTransInstructionDao#saveFlightTransInstruction(FlightTransInstruction flightTransInstruction)
     */    
    public int saveFlightTransInstruction(final FlightTransInstruction flightTransInstruction) {
        Integer id = flightTransInstruction.getId();
        // check for new record
        if (id == null) {
            id = (Integer) getSqlMapClientTemplate().insert("addFlightTransInstruction", flightTransInstruction);
        } else {
            getSqlMapClientTemplate().update("updateFlightTransInstruction", flightTransInstruction);
        }
        if( id == null ) {
            throw new ObjectRetrievalFailureException(FlightTransInstruction.class, id);
        }
        return id.intValue();
    }

    /**
     * @see com.sasis.dao.FlightTransInstructionDao#removeFlightTransInstruction(Integer id)
     */
    public void removeFlightTransInstruction(FlightTransInstruction flightTransInstruction) {
        getSqlMapClientTemplate().update("deleteFlightTransInstruction",  flightTransInstruction);
    }
}
